/* ActorRepository.java
 *
 * Copyright (C) 2013 Universidad de Sevilla
 * 
 * The use of this project is hereby constrained to the conditions of the 
 * TDG Licence, a copy of which you may download from 
 * http://www.tdg-seville.info/License.html
 * 
 */

package repositories;

import java.util.Collection;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import domain.Route;

@Repository
public interface RouteRepository extends JpaRepository<Route, Integer> {
	@Query("select a.routes from Administrator a where a.id = ?1")
	Collection<Route> findRoutesByAdministrator(int id);

	@Query("select r from Route r order by r.rating DESC")
	Collection<Route> findAllOrderedByRating();

	@Query("select r from Route r where r.event.id=?1")
	Collection<Route> findByEventId(int id);

	@Query("select r from Administrator a join a.routes r where a.id=?1 order by r.rating DESC")
	Collection<Route> findByAdministratorOrderedByRating(int id);

	@Query("select route from Registration r join r.event.routes route where r.participant.id=?1 order by route.rating DESC")
	Collection<Route> findByParticipantOrderedByRating(int id);
}